package com.example.controller.configuration;

import com.example.bean.configuration.PingGuJiBieGuanLi;
import com.example.bean.configuration.PingGuMoBan;
import com.example.bean.configuration.vo.PingGuJiBieGuanLiVo;
import com.example.bean.configuration.vo.PingGuMoBanVo;
import com.example.service.configuration.PingGuJiBieGuanLiService;
import com.example.utils.Result;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/pinggujibieguanli")
public class PingGuJiBieGuanLiController {

    @Autowired
    PingGuJiBieGuanLiService service;

    @PostMapping("/page")
    public PageInfo<PingGuJiBieGuanLi> page(@RequestBody PingGuJiBieGuanLiVo vo){
        return service.getpage(vo);
    }

    @PostMapping("/addpgjbgl")
    public Result addpgjbgl(@RequestBody PingGuJiBieGuanLi pingGuJiBieGuanLi){
        Integer flag = service.addpgjbgl(pingGuJiBieGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    @GetMapping("/{aid}")
    public Result getById(@PathVariable String aid){
        PingGuJiBieGuanLi pingGuJiBieGuanLi = service.getId(aid);
        Result result = new Result();
        if(pingGuJiBieGuanLi != null){
            result.ok();
            result.setData(pingGuJiBieGuanLi);
        }else {
            result.fail("失败");
        }
        return result;
    }

    @PutMapping("/updatepgjbgl")
    public Result update(@RequestBody PingGuJiBieGuanLi pingGuJiBieGuanLi){
        System.out.println(pingGuJiBieGuanLi);
        Integer flag = service.xiugai(pingGuJiBieGuanLi);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else{
            result.fail("失败");
        }
        return result;
    }

    //批量删除
    @PostMapping("/dels")
    public Result dels(@RequestBody List<String> ids){
        //删除
        Integer flag =  service.dels(ids);
        Result result = new Result();
        if(flag > 0){
            result.ok();
        }else {
            result.fail("失败");
        }
        return result;
    }
}
